# -*- coding: utf-8 -*-
#music code be here

import pyglet

can_has_music = True
can_has_sfx = True

music_player = pyglet.media.Player()
music_player.eos_action = music_player.EOS_LOOP

sfx_player = pyglet.media.Player()

sfx = {"explosion" : pyglet.resource.media("bomm.ogg", False),
    "death" : pyglet.resource.media("soldier_death.ogg", False),
}


def play_background(songname):
    if not can_has_music:
        return
    try:
        song = pyglet.resource.media(songname)
    except pyglet.resource.ResourceNotFoundException:
        return
    music_player.queue(song)
    if music_player.playing:
        music_player.next()
    else:
        music_player.play()
    
def stop():
    music_player.pause()

def start():
    music_player.play()

def play_sfx(name):
    global can_has_sfx
    if name in sfx and can_has_sfx:
        try: #there has been errors here
            sfx_player.queue(sfx[name])
            if sfx_player.playing:
                sfx_player.next()
            else:
                sfx_player.play()
        except:
            can_has_sfx = False
            #make superquickfix